package ecmnext.utils;

/***************************************************************/
/*                     SOFTWARE SECTION                        */
/***************************************************************/
/*
 * <p>Name: ECMNext</p>
 * <p>Description: Simulation of the platform of trading Software</p>
 * <p>Licence: General Public License</p>
 * <p>Organisation: EC Marseille</p>
 * <p>Persons involved in the project : groupe Plateforme de Trading</p>
 * <p>Current version: 1.0</p>
 */

/***************************************************************/
/*                      IMPORT SECTION                         */
/***************************************************************/

import java.awt.event.*;
import javax.swing.*;

/***************************************************************/
/*                  PopupListener Class Section                */
/***************************************************************/
/**
 * <p>Title : PopupListener</p>
 * <p>Description : </p>
 * @author Xuewen YANG ET Antoine COUDERC
 * @version 1.0
 */

public class PopupListener extends MouseAdapter {

  JPopupMenu popup;

  public PopupListener(JPopupMenu popup) {
    this.popup = popup;
  }

  public void mousePressed(MouseEvent e) {
    maybeShowPopup(e);
  }

  public void mouseReleased(MouseEvent e) {
    maybeShowPopup(e);
  }

  private void maybeShowPopup(MouseEvent e) {
    if (e.isPopupTrigger()) {
      popup.show(e.getComponent(), e.getX(), e.getY());
    }
  }
}
